import { Button, Drawer, Popover, List, Radio, Tag } from 'antd';
import React, { useEffect, useState } from 'react';
import ReactDOM from 'react-dom';
import { baseData } from '../init';
import Move from '../Move'
import { CopyOutlined, SyncOutlined, UserOutlined } from '@ant-design/icons'
// NCC页面右侧按钮栏
export function Toolbar() {   
    let NCCPage = (
        <React.Fragment>
            {/* <Button onClick={() => { QiYeJiXiao() }} title="企业绩效管理">企业绩效管理</Button> */}
            {/* <Button onClick={() => { refresh() }} title="刷新"><SyncOutlined /></Button> */}
            <Button onClick={(e) => { e.stopPropagation(); copyPageInfo() }} title="复制节点入口路径"><CopyOutlined /></Button>
        </React.Fragment>
    )
    // 判断是jira还是NCC
    let content = window.top.location.href.includes('pm.yyrd.com')  ? null : NCCPage
    return (
        <Move style={{left:0,bottom:'400px'}}>
            <div className='NCCPageBtns' style={{}}>
                {content}
            </div>
        </Move>
    )
}
// 给复制按钮定位
export function NccInit() {
    // n-v-middle
    // setInterval(() => {
    //     let nav = window.top.document.querySelector('.n-v-middle')
    //     if (nav) {

    //     }
    // }, 1000);

}

// 复制方法
function copyStr(content, message) {
    try {
        
        var url = content; //复制的网址或内容
        var aux = document.createElement('input');
        aux.setAttribute('value', url);
        document.body.appendChild(aux);
        aux.select();
        document.execCommand('Copy'); //原生copy方法执行浏览器复制命令
        document.body.removeChild(aux); //清除input
        if (message == null) {
            /* 复制失败消息 */
        } else {
            /* 复制成功消息 */
        }
    } catch (error) {
        
    }
}
function copyPageInfo() {
    let { src, contentWindow: { location } } = baseData.mainIframe;
    try {
        let res = src.split('resources')[1].split('html')[0]
        copyStr(`${res}js`);
    } catch (error) {
        copyStr(src.split(location.port)[1].split('html')[0] + 'js');
    }
    // 判断是内部页签模式
    let iframeArr = [...document.querySelectorAll('.nc-iframe-container')]
    if (iframeArr.length) {
        let targetIframeSrc = iframeArr.find(item => item.style.display === 'block').querySelector('iframe').getAttribute('src').split('html')[0].replace('../../../../', '')
        copyStr(targetIframeSrc);

    }

}
